<?php
ob_start(); 
session_start();

session_unregister('error');
function getlang(){
		$lang = $_SESSION['lang'];
		if (empty($lang) || $lang == "KR") {
			$value = "value/value_kr.php";
		} else if($lang == "VN") {
			$value = "value/value_vn.php";
		}
		else if($lang == "EN"){
			$value = "value/value_en.php";
		}
		return $value;
	}
	
	$value = getlang();
	include($value);
if(isset($_REQUEST['Dangnhap'])){
	$tkemail = $_REQUEST['email'];
	
	$passwd= $_REQUEST['passwd'];
	$check= $_REQUEST['check'];
	
	if(empty($tkemail))
		$_SESSION['error']=$errorLogin1;
	else if(empty($passwd))
		$_SESSION['error']=$errorLogin2;
	else{
		include 'connection/connection.php';
		
		$passwd = md5($passwd);
			
		$query = mysql_query("select role from user_info where email='$tkemail' and passwd = '$passwd'");
		$co=0;
		while ($row=mysql_fetch_array($query)){
			$co=1;
		    if($_REQUEST['check'] == "on"){// Da tick
		    	setcookie("tkemail",$tkemail,time()+60*60*24*30);
		    	//setcookie("tkemailrestore",$row['emailrestore'],time()+200000);
		    	setcookie("role",$row['role'],time()+60*60*24*30);
		    }
		    else{ 
		    	setcookie('tkemail');
		    	//setcookie("tkemailrestore");
		    	setcookie("role");
		    } 
		    $_SESSION['tkemail']=$tkemail;
		    //$_SESSION['tkemailrestore']=$row['emailrestore'];
		    $_SESSION['role']=$row['role'];
		    $_SESSION['action']='hoso';
		  	//echo $_SESSION['role'];
		}
		if($co==0)
			$_SESSION['error']=$errorLogin3;
		mysql_connect($connection);
	}
	header( 'Location: index.php' );
	
	
	
}
if(isset($_REQUEST['Dangxuat'])){
	session_unregister('tkemail');
	setcookie('tkemail'); 
	//session_unregister('tkemailrestore');
	//setcookie('tkemailrestore'); 
	session_unregister('role');
	setcookie('role'); 
	if($_SESSION['action']=='hoso' || $_SESSION['action']=='giayphep')
		$_SESSION['action']='home';
	header( 'Location: index.php' );
}
	
	
ob_flush();
?>